Reading list Switch to dark mode

    How to use {url} for links creation on tpl files in Prestashop 1.7

    Updated 17 January 2022

    In this blog, we will learn new standards of links creation on tpl files in Prestashop 1.7 .

    In Prestashop 1.6 we used {$link} variable on tpl files and we created links on tpl files by calling different link creation methods from $link object.

    But in Prestashop 1.7, a new standard has been set to create links on tpl files. Now we will use {url} for different kind of links creation on tpl files in Prestashop 1.7.

    Let’s understand it with some examples to know how to replace {$link} of Prestashop 1.6 with {url} in Prestashop 1.7 –

    Prestashop 1.6 : {$link->getModuleLink()}
    Prestashop 1.7 : {url entity='module' name='myModule' controller='myController' params = ['paramKey1' => $paramValue1, 'paramKey2' => $paramValue2]}
    Example : {url entity='module' name='marketplace' controller='productupdate' params=['edited' => 1, 'id' => $id]}
    
    Prestashop 1.6 : {$link->getPageLink()}
    Prestashop 1.7 : { url entity='myPageName' params = ['paramKey1' => $paramValue1, 'paramKey2' => $paramValue2]}
    Example : { url entity='my-account' params=['edited' => 1, 'id' => $id]}
    
    Prestashop 1.6 : {$link->getCategoryLink()}
    Prestashop 1.7 : {url entity='category' id=$id_category id_lang=$id_lang}
    Example : {url entity='category' id=3 id_lang=2}
    
    Prestashop 1.6 : {$link->getCmsLink()}
    Prestashop 1.7 : {url entity='cms' id=$id_cms id_lang=$id_lang}
    Example : {url entity='cms' id=3 id_lang=2}
    
    Prestashop 1.6 : {$link->getCatImageLink()}
    Prestashop 1.7 : {url entity='categoryImage' id=$id_category name='imageType'}
    Example : {url entity='categoryImage' id=3 name='home-default'}

    Symfony URLs with {url}

    You can also create Symfony URLs using {url} in Prestashop 1.7

    Searching for an experienced
    Prestashop Company ?
    Find out More
    //link for admin order view page
    <a href="{url entity='sf' route='admin_orders_view' sf-params=["orderId"=>"$id_order"] }"> Link to admin order page <a/>

    You have to pass

    entity : ‘sf’ for symfony url

    route : name of the symfony route (admin_orders_view) in the route parameter

    sf-params : link parameters for symfony url.

    So this is how you can use {url} in Prestashop 1.7 for links creation in tpl files.

    Note-  {url} is directly linked to the getUrlSmarty($params) in the “classes/Link.php” . So you can check this function for more information on links creations iwth {url}.

    You can also take a reference on this topic by visiting the following link –

    Reference – http://developers.prestashop.com/themes/smarty/helpers.html

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    3 comments

  • Ivan
    • Mehul Gupta (Moderator)
  • Andrea Testa
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home